import { defineStore } from 'pinia';
//引入请求函数
import { reqLogin, reqLogout } from '../api/login/index'


const userInfoStore = defineStore('userInfo', {
    state: () => ({
        token: ''
    }),
    actions: {
        //用户登录
        async login(loginParams: any) {
            //发送请求获取用户token
            let result = await reqLogin(loginParams)
            console.log("result", result)
            //持久化存储token
            localStorage.setItem('token', result.data.data.token)
            console.log(result.data.data.token);

            // console.log("result", result)
            this.token = result.data.token
            setTimeout(() => {
                window.location.reload()

            }, 100)
        },
        //退出登录
        async logout() {
            await reqLogout()
            //删除token
            localStorage.removeItem('token')
            window.location.reload()
        }
    }
})
export default userInfoStore